import { GlobalData } from "./GlobalData";

const { ccclass, property } = cc._decorator;

const ScaleType = cc.Enum({
    Horizozntal: 1,     //横向
    Vertical: 2,        //纵向
});

/** 整体缩放适配 手机屏幕大小 */
@ccclass
export default class AdapItem extends cc.Component {
    @property({ type: cc.Enum(ScaleType), displayName: "缩放方向" })
    private scale_Type: number = ScaleType.Vertical;
    @property({ type: cc.Float, displayName: "最小值" })
    private minScale: number = 0.1;
    @property({ type: cc.Float, displayName: "最大值" })
    private maxScale: number = 1;

    protected onLoad() {
        this.initView();
    }

    private initView() {
        const size = cc.view.getVisibleSize();
        GlobalData.stage_width = size.width;
        GlobalData.stage_height = size.height;

        const widthScale = size.width / GlobalData.design_width;
        const heightScale = size.height / GlobalData.design_height;
        if (size.height / size.width <= 1.67) {
            GlobalData.fixType = '高适配';
            this.node.scale = heightScale;
        } else {
            GlobalData.fixType = '宽适配';
            this.node.scale = widthScale;
        }

        // let toScale = 1;
        // if (this.scale_Type == ScaleType.Horizozntal) {
        //     toScale = GlobalData.stage_width / GlobalData.design_width;
        // }
        // if (this.scale_Type == ScaleType.Vertical) {
        //     toScale = GlobalData.stage_height / GlobalData.design_height;
        // }
        // toScale = Math.min(toScale, this.maxScale);
        // toScale = Math.max(toScale, this.minScale);
        // this.node.scale = toScale;
        // // console.log("toScale:", toScale);
    };
}